﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Cheetah_Fast_Banking_App
{
    public class TransactionComparer : IComparer<Transaction>
    {
        // evil bank algorithm
        public int Compare(Transaction x, Transaction y)
        {
            DateTime xDate = new DateTime(x.Date.Year, x.Date.Month, x.Date.Day);
            DateTime yDate = new DateTime(y.Date.Year, y.Date.Month, y.Date.Day);

            if (xDate != yDate)
                return (int)(xDate - yDate).TotalDays;

            if (x.Amount > y.Amount)
                return 1;
            else if (x.Amount > y.Amount)
                return -1;

            return 0;
        }
    }
}
